package com.cgsd.heyu.ui.task.adapter;

import com.android.library.image.GlideUtil;
import com.cgsd.heyu.R;
import com.cgsd.heyu.ui.task.vo.PayTypeVo;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

/**
 * Author: sky on 2021/3/30 11:31
 * Email: xcode126@126.com
 * Desc: 支付方式选择
 */
public class PayTypeAdapter extends BaseQuickAdapter<PayTypeVo, BaseViewHolder> {

    private int selected;

    public PayTypeAdapter() {
        super(R.layout.item_pay_type);
    }

    @Override
    protected void convert(BaseViewHolder helper, PayTypeVo item) {
        helper.setText(R.id.tv_title, item.text);
        GlideUtil.loadRemoteImage(mContext, item.icon, helper.getView(R.id.iv_image));
        helper.getView(R.id.iv_select).setSelected(helper.getAdapterPosition() == selected);
    }

    public void setSelected(int selected) {
        this.selected = selected;
        notifyDataSetChanged();
    }

    public int getSelected() {
        if (mData != null && mData.size() > 0) {
            return mData.get(selected).id;
        }else {
            return -1;
        }
    }
}
